package playGround;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;

import java.math.BigDecimal;

import org.junit.*;



public class SquareTest {
	
	private Square square;
	private Square square1;
	private Square square2;
	private Square square3;
	@Before
	public void setUp() throws Exception {
		square = new Square();
		square1 = new Square();
		square2 = new Square(300,new BigDecimal(10), Scale.CELCIUS,0.2f);
		square3 = new Square(-50,new BigDecimal(10), Scale.CELCIUS,0.2f);
	}

	@After
	public void tearDown() throws Exception {
	}
	
	 @Test
	public void testColdDamageNull(){
		
		assertEquals(0,square.getColdDamage());
	}
	@Test
	public void testMergeWithBordersEnd(){
		square.mergeWith(6, square1);
		assertEquals(false,square.getBorder(6));
		assertEquals(false,square1.getBorder(1));
	}
	@Test
	public void testMergeWithBordersMid(){
		square.mergeWith(3, square1);
		assertEquals(false,square.getBorder(3));
		assertEquals(false,square1.getBorder(4));
	}
	@Test(expected = IndexOutOfBoundsException.class)
	public void testMergeWithBordersFalseToHigh(){
		square.mergeWith(7, square1);
	}
	@Test(expected = IllegalArgumentException.class)
	public void testMergeWithBordersAlreadyTaken(){
		square.mergeWith(4, square1);
		square.mergeWith(4, square1);
	}
	@Test
	public void testMergeWithDifferentScale(){
		Square square4 = new Square(100,new BigDecimal(10), Scale.KELVIN,0.2f);
		square.mergeWith(4, square4);
		assertEquals(false,square.getBorder(4));
		assertEquals(false,square4.getBorder(3));
	}
	@Test
	public void testMergeWithCalculations(){
		Square square5 = new Square(100,new BigDecimal(20), Scale.CELCIUS,0.2f);
		Square square6 = new Square(400,new BigDecimal(60), Scale.CELCIUS,0.2f);
		square5.mergeWith(3, square6);
		assertEquals(260, square5.getTemperature());
	}
	@Test
	public void testHeatDamage() {
		int dmg = square2.getHeatDamage();
		dmg=0;
		assertNotSame(dmg,square2.getHeatDamage());
	}
	@Test
	public void testColdDamage() {
		int dmg = square3.getColdDamage();
		dmg=0;
		assertNotSame(dmg,square3.getColdDamage());
	}
	@Test
	public void testRustDamage() {
		square2.setHumidity(new BigDecimal(2));
		assertEquals(square2.getRustDamage(),0);
	}
	@Test
	public void testScaleKelvin(){
		int value = Scale.changeScale(Scale.KELVIN, Scale.CELCIUS, 0);
		assertEquals(-273,value);
	}
	@Test
	public void testScaleFahrenheit(){
		int value = Scale.changeScale(Scale.CELCIUS, Scale.FAHRENHEIT, 0);
		assertEquals(32,value);
	}
	@Test
	public void testScaleCelcius(){
		int value = Scale.changeScale(Scale.CELCIUS, Scale.KELVIN, 20);
		assertEquals(293,value);
	}
	@Test
	public void testChangeScale(){
		square2.changeScale(Scale.KELVIN);
		assertEquals(573,square2.getTemperature());
	}
	@Test
	public void testHeatConstant() {
		Square square4 = new Square(100,new BigDecimal(20), Scale.CELCIUS,0.1f);
		assertNotSame(Square.getHeatConstant(),0.2f);
	}
	
		
}
